(function() {
    'use strict';

    /**
     * @ngdoc function
     * @name webApp.controller:MainCtrl
     * @description
     * # MainCtrl
     * Controller of the webApp
     */
    angular.module('webApp')
        .controller('BuyerCtrl', BuyerCtrl);

    BuyerCtrl.$inject = ['$scope', 'dataService','helper','$rootScope','USER_ROLES','$timeout','$state'];

    function BuyerCtrl($scope, dataService,helper,$rootScope,USER_ROLES,$timeout,$state) {
            $scope.init = function() {
                    $scope.currentUser = null;
                    $scope.userRoles = USER_ROLES;
                    //初始化
                    if (!window.localStorage.lang) {
                        window.localStorage.lang = 'zh-cn';
                    }
                    //语言设定
                    // $scope.cur_lang = window.localStorage.lang;

                    $timeout(function() {
                        if (!$rootScope.currentUser) {
                            $rootScope.getUserInfo(true);
                        }
                    }, 1000);
                }
        $scope.registerAddaction=function(){

        }
         $scope.register=function(){
            // var dialog = new auiDialog({});
            // dialog.close();
            // console.log("11",dialog);
         }
       
        $scope.loginAdd=function(){
            //,phone:$scope.phone,email:$scope.email
            var data={user_name:$scope.user_name,password:$scope.password,password_confirm:$scope.password_confirm};
            dataService.buyerRegister(data).then(function(result){
                console.log(result);
                if(result.Msg){
                    console.log("111");
                    helper.myAlert("error："+result.Msg);
                }else if (result && result.user_id) {
                            $state.go("main");
                            $rootScope.$broadcast('event:auth-shoploginRequired');
                }
            })
        }
    }
})();